<?php
//include(__APP_PATH . '/model/gallery.class.php');
//include(__APP_PATH . '/model/comment.class.php');
//include(__APP_PATH . '/model/image.class.php');

$comments = $oGallery->getCommentsById($registry->router->args[0]);
$image = $oGallery->getImageById($registry->router->args[0]);
$prevID = ($registry->router->args[0] > 0) ? $registry->router->args[0] - 1 : $oGallery->getImageQuantity() - 1;
$nextID = ($oGallery->isPhoto($registry->router->args[0] + 1)) ? $registry->router->args[0] + 1 : 0;
?>
<div id="image">
	<div id="imageView">
		<div class="imageItem"><?php echo '<img src="' . $registry->__get("url_path") . 'photos/original/' . $image->getFilename() . '" width="940" />'; ?></div>
		<span class="caption">Caption: <?php echo $image->getCaption(); ?></span>
		<span class="buttons">
			<a href="<?php echo $registry->__get("url_path") . 'image/view/' . $prevID?>"><button type="button">Föregående</button></a>
			<a href="<?php echo $registry->__get("url_path") . 'image/view/' . $nextID?>"><button type="button">Nästa</button></a>
		</span>
	</div>
	<div id="comments">
		<h3>Kommentarer</h3>
		<?php
		if($comments != null) { 
			foreach($comments as $comment) {
				echo '<div class="commentItem">';
					echo '<strong class="commentName">' . $comment->getName() . '</strong><br />';
					echo '<span class="timestamp">' . $comment->getTimestamp() . '</span>';
					echo '<span class="rating">' . $comment->getRating() . '</span>';
					echo '<p class="commentText">' . $comment->getText() . '</p>';
				echo '</div>';
			}
		} else {
			echo 'Det finns inga kommentarer';
		}
		?>
		</div>
	</div>
	<div id="commentform">
		<?php echo $form_message; ?>
		<form method="post" action="<?php echo $registry->__get("url_path") . "image/view/" . $registry->router->args[0]; ?>">
			<input type="hidden" id="imageId" name="imageId" value="<?php echo $registry->router->args[0]; ?>" />
			<label for="commentName">Namn:</label>
			<input type="text" id="commentName" name="commentName" value="<?php echo $params['name']; ?>" />
			
			<label for="commentEmail">E-mail:</label>
			<input type="text" id="commentEmail" name="commentEmail" value="<?php echo $params['email']; ?>" />
			
		    <label for="commentText">Din kommentar</label><br />
		    <textarea id="commentText" name="commentText"><?php echo $params['text']; ?></textarea><br />
			
			<label for="commentRating">Betyg:</label>
			<select id="commentRating" name="commentRating">
			<option value="-" <?php if($params['rating'] == null) { echo 'selected="selected"'; } ?>>-</option>
				<?php 
				for ($i = 1; $i < 6; $i++) {
					if($i == $params['rating']) {
						echo '<option value="' . $i . '" selected="selected">' . $i . '</option>';
					}  else {
						echo '<option value="' . $i . '">' . $i . '</option>';				
					}
				}
				?>
			</select>
			
			<label for="submit">Tänka först, posta sen :D</label>
		    <input type="Submit" name="submit" id="submit" value="Kommentera" />
		</form>
	</div>
</div>